<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Game</title>
    <style>
        * {
            margin:0;
            padding: 0;
        }

        button {
            display: inline-block;
        }
    </style>
</head>
<body>
        <div id="output" style="height: 400px; width: 600px; background: #eee">
            </div>
            <button id="rock" style="height: 40px; width: 80px">石头</button>
            <button id="scissor" style="height: 40px; width: 80px">剪刀</button>
            <button id="paper" style="height: 40px; width: 80px">布</button>
    <script>
        const $button = {
            rock: document.getElementById('rock'),
            scissor: document.getElementById('scissor'),
            paper: document.getElementById('paper')
        }


    const $output = document.getElementById('output')
    Object.keys($button).forEach(key =>{
        $button[key].addEventListener('click',function(){
            fetch(`http://${location.host}/game?action=${key}`).then(
                (res)=>{
                    return res.text();
                })
                .then(
                    (text)=>{
                        $output.innerHTML+=text+'<br/>';
                })
        })
    })
    </script>
</body>
</html>